<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Vue组件</title>
  <script src="./js/vue.global.js"></script>
  <style>
    button {
      display: block;
      margin-top: 10px;
    }

    span {
      display: block;
      margin-top: 3px;
      width: 177px;
      height: 20px;
      background-color: antiquewhite;
    }
  </style>
</head>
<!-- 假设没有v-model,如何实现？ -->

<body>
  <div id="Application">
    <my-input v-model="inputText"></my-input>
    <span>{{inputText}}</span>
    <button @click="this.inputText = ''">清空</button>
  </div>
  <script>
    const App = Vue.createApp({
      data() {
        return {
          inputText: "",
        };
      },
      methods: {
        action(event) {
          this.inputText = event.target.value;
        },
      },
    });

    const inputComp = {
      data() {
        return {
          inputText: ''
        }
      },
      props: ["modelValue"],
      methods: {
        action(event) {
          this.inputText = event.target.value
          this.$emit('update:modelValue', event.target.value)
        }
      },
      template: `
        <div>
          <span>输入框:</span>
          <input :value="inputText" 
        placeholder="v-model测试" 
        @input="action" />  
        </div>
       `
    }

    App.component("my-input", inputComp);
    App.mount("#Application");
  </script>
</body>

</html>